﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{
    public class Vendor : BaseRepository<VendorInfo>, IVendor
    {
        #region 静态变量部分
        private const string PARM_VENDOR_ID = "@VendorID";
        private const string PARM_VENDOR_NAME = "@VendorName";
        #endregion

        #region 数据检索部分
        public IList<VendorInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("Vendor_select", null);
        }

        public VendorInfo LoadEntity<T1>(T1 vendorId)
        {
            //Create a parameter    
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = vendorId;

            //Execute the query	
            return ExcuteSqlToGetEntity("Vendor_selectbyID", parm);
        }
        #endregion

        #region 重写基类部分
        public override VendorInfo GetEntityRecord(SqlDataReader rdr)
        {
            VendorInfo pro = new VendorInfo() { VendorID = rdr.GetValue(0).ToString(), VendorName = rdr.GetValue(1).ToString() };
            return pro;
        }

        public override VendorInfo GetEntityRecord()
        {
            VendorInfo pro = new VendorInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "Vendor_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return "Vendor_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_VENDOR_ID, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_VENDOR_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_VENDOR_NAME, SqlDbType.NVarChar, 50)
                };
            return parms;
        }

        public override void SetParameters(VendorInfo vendor, params SqlParameter[] Parms)
        {
            Parms[0].Value = vendor.VendorID;
            Parms[1].Value = vendor.VendorName;
        }
        #endregion
    }
}
